#include "head.h"

void user_init(client_t *cl, MYSQL *conn){
    char buf[1024] = { 0 };
    sprintf(buf, "select user_name from user where id = %d", cl->user_ID);

    if (mysql_query(conn, buf)) {
        printf("%s\n", mysql_error(conn));
        return;
    }
    MYSQL_RES *result;
    MYSQL_ROW row;
    result = mysql_store_result(conn);
    row = mysql_fetch_row(result);
    mysql_free_result(result);
    strcpy(cl->name, row[0]);


    sprintf(buf, "select id, path from file where user_name = '%s' and father_id = -1", cl->name);

    if (mysql_query(conn, buf)) {
        printf("%s\n", mysql_error(conn));
        return;
    }
    result = mysql_store_result(conn);
    row = mysql_fetch_row(result);
    mysql_free_result(result);
    cl->file_id = atoi(row[0]);
    strcpy(cl->dir_path, row[1]);
}
